package com.chengyu.core.service.services.impl;

import cn.hutool.core.date.DateUtil;
import com.chengyu.core.mapper.PmsServicesParamsMapper;
import com.chengyu.core.model.PmsServicesParams;
import com.chengyu.core.model.PmsServicesParamsExample;
import com.chengyu.core.service.services.ServicesParamsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @title  商品属性
 * @author wenlj
 * @date   2022/4/25
 */
@Service
public class ServicesParamsServiceImpl implements ServicesParamsService {

	@Autowired
	private PmsServicesParamsMapper servicesParamsMapper;

	@Override
	public List<PmsServicesParams> getServicesParamsList(Integer servicesId) {
		PmsServicesParamsExample example = new PmsServicesParamsExample();
		example.setOrderByClause("sort asc");
		example.createCriteria().andServicesIdEqualTo(servicesId);
		return servicesParamsMapper.selectByExample(example);
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRED, rollbackFor=Exception.class)
	public void addServicesParams(PmsServicesParams servicesParams) {
		servicesParams.setUpdTime(DateUtil.date());
		if(servicesParams.getId() == null){
			servicesParamsMapper.insert(servicesParams);
		}else{
			servicesParamsMapper.updateByPrimaryKeySelective(servicesParams);
		}
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRED, rollbackFor=Exception.class)
	public void deleteServicesParams(Integer id) {
		servicesParamsMapper.deleteByPrimaryKey(id);
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRED, rollbackFor=Exception.class)
	public void deleteServicesParamsByServicesId(Integer servicesId) {
		PmsServicesParamsExample example = new PmsServicesParamsExample();
		example.createCriteria().andServicesIdEqualTo(servicesId);
		servicesParamsMapper.deleteByExample(example);
	}
}